// !@#$McCaBe-InStRuMeNtAtIoN$#@!
// Instrumented with the McCabe Java Parser
// Version: 8.1.0.1 - 20110309
// Using Path Vector Instrumentation
// Date: Sun Apr 01 2012 20:42:00
package Model;

import java.text.SimpleDateFormat;
import java.util.Date;

import com.mccabe.*;


class Event_4f0a931657296fb3a318543c2ea14079 {
    static java.lang.Object info[];
    static {
        info = new java.lang.Object[2];
        info[0] = new Integer(-1);
        info[1] = new String("R:\\yu\\Concordia\\SOEN 344 Design II\\Term Assignment\\Code Repo\\trunk\\Iteration 3\\ERS\\src\\Model\\Event.java");
    }
}


/**
 * Event Class, occurrence of EventSpecification abstraction class.
 * 
 * @author Yury Kitaev
 *
 */
public class Event 
{

	private static int nextEventId = 1000;
	private int id;
	private Date date; // date and time
	private int duration; // in minutes
	private int capacity; // in persons
	private EventSpecification specification; 
	private EventStatus status;
	private VenueTimeslot venue;
	private int seatsTaken;
	
	/** 
	 * Constructor 
 	 * @param date The date and time of the event start
	 * @param duration Duration of the event, in minutes
	 * @param capacity Maximum number of attendees
	 * @param specification Event Specification class
	 * @param venue The venue where the event is held
	 */
	public Event(Date date, int duration, int capacity,
			EventSpecification specification, EventStatus status, VenueTimeslot venue)
	{
		super();
int _mcFreq_181aeadf0e2abb133f165ad7b6ecba0e[] = PathVec_ERS_Iter3.getIntArray(0);
PathVec_ERS_Iter3.releaseIntArray();
PathVec_ERS_Iter3.enterConstructorWithECC(Event_4f0a931657296fb3a318543c2ea14079.info,0,_mcFreq_181aeadf0e2abb133f165ad7b6ecba0e,0);

		this.date = date;
		this.duration = duration;
		this.capacity = capacity;
		this.specification = specification;
		this.status = status;
		this.venue = venue;
		this.id = (nextEventId++);
		seatsTaken = 0;
	}

	public Date getDate() 
	{
int _mcFreq_96daff82c5afb20024fd34f129d66ca6[] = new int[1];
PathVec_ERS_Iter3.enterMethod(Event_4f0a931657296fb3a318543c2ea14079.info,1,_mcFreq_96daff82c5afb20024fd34f129d66ca6,0);

		return date;
	}

	public void setDate(Date date) 
	{
int _mcFreq_1c3c557b4a2401a15e065f847b252218[] = new int[1];
PathVec_ERS_Iter3.enterMethod(Event_4f0a931657296fb3a318543c2ea14079.info,2,_mcFreq_1c3c557b4a2401a15e065f847b252218,0);

		this.date = date;
	}

	public int getDuration() 
	{
int _mcFreq_eefb7e1b2656a884417267c0b94ec08e[] = new int[1];
PathVec_ERS_Iter3.enterMethod(Event_4f0a931657296fb3a318543c2ea14079.info,3,_mcFreq_eefb7e1b2656a884417267c0b94ec08e,0);

		return duration;
	}

	public void setDuration(int duration) 
	{
int _mcFreq_2e90cc5868d0d80e7f88be9e7f59ca27[] = new int[1];
PathVec_ERS_Iter3.enterMethod(Event_4f0a931657296fb3a318543c2ea14079.info,4,_mcFreq_2e90cc5868d0d80e7f88be9e7f59ca27,0);

		this.duration = duration;
	}

	/**
	 * Maximum number of people allowed in.
	 * @return
	 */
	public int getCapacity() 
	{
int _mcFreq_b03e53695f0abbb1760e445eae9eab07[] = new int[1];
PathVec_ERS_Iter3.enterMethod(Event_4f0a931657296fb3a318543c2ea14079.info,5,_mcFreq_b03e53695f0abbb1760e445eae9eab07,0);

		return capacity;
	}

	public void setCapacity(int capacity)
	{
int _mcFreq_cae6fd6f91f2d5d5437ffd17c4ec7952[] = new int[1];
PathVec_ERS_Iter3.enterMethod(Event_4f0a931657296fb3a318543c2ea14079.info,6,_mcFreq_cae6fd6f91f2d5d5437ffd17c4ec7952,0);

		this.capacity = capacity;
	}

	/**
	 * Tells if the event is open or closed
	 * @return
	 */
	public EventStatus getStatus() 
	{
int _mcFreq_b4f211cbe08cb0cb58c7a8905529784e[] = new int[1];
PathVec_ERS_Iter3.enterMethod(Event_4f0a931657296fb3a318543c2ea14079.info,7,_mcFreq_b4f211cbe08cb0cb58c7a8905529784e,0);

		return status;
	}

	/**
	 * Opens or closes the event
	 * @param status Any value from EventStatus enum
	 */
	public void setStatus(EventStatus status) 
	{
int _mcFreq_3b6e9c17a48b993259f1822363f2d8d1[] = new int[1];
PathVec_ERS_Iter3.enterMethod(Event_4f0a931657296fb3a318543c2ea14079.info,8,_mcFreq_3b6e9c17a48b993259f1822363f2d8d1,0);

		this.status = status;
	}

	public VenueTimeslot getVenue() 
	{
int _mcFreq_1a7272477c8d77de7eb3683099cf00ee[] = new int[1];
PathVec_ERS_Iter3.enterMethod(Event_4f0a931657296fb3a318543c2ea14079.info,9,_mcFreq_1a7272477c8d77de7eb3683099cf00ee,0);

		return venue;
	}

	public void setVenue(VenueTimeslot venue) 
	{
int _mcFreq_8961161c4c7a0a47d681e2cefbffa7b3[] = new int[1];
PathVec_ERS_Iter3.enterMethod(Event_4f0a931657296fb3a318543c2ea14079.info,10,_mcFreq_8961161c4c7a0a47d681e2cefbffa7b3,0);

		this.venue = venue;
	}

	public int getId() 
	{
int _mcFreq_e0fce58cc7a10ce2f11950284e4306be[] = new int[1];
PathVec_ERS_Iter3.enterMethod(Event_4f0a931657296fb3a318543c2ea14079.info,11,_mcFreq_e0fce58cc7a10ce2f11950284e4306be,0);

		return id;
	}

	public EventSpecification getSpecification() 
	{
int _mcFreq_b182446ac7b70e5f3e5bf060facd93d9[] = new int[1];
PathVec_ERS_Iter3.enterMethod(Event_4f0a931657296fb3a318543c2ea14079.info,12,_mcFreq_b182446ac7b70e5f3e5bf060facd93d9,0);

		return specification;
	}

	public void setSpecification(EventSpecification specification) 
	{
int _mcFreq_b18577bb64d73fa88b463b8492358873[] = new int[1];
PathVec_ERS_Iter3.enterMethod(Event_4f0a931657296fb3a318543c2ea14079.info,13,_mcFreq_b18577bb64d73fa88b463b8492358873,0);

		this.specification = specification;
	}
	
	/**
	 * Closes the event if all seats are taken or if the amount of seats exceeds the capacity
	 */
	public void refreshStatus()
	{
int _mcFreq_d33a41ac104e8c48ca6c8782b5f11bc3[] = new int[9];
PathVec_ERS_Iter3.enterMethod(Event_4f0a931657296fb3a318543c2ea14079.info,14,_mcFreq_d33a41ac104e8c48ca6c8782b5f11bc3,0);

		int numberOfSeatsTaken = 0;
		
{
for (Seat s : getVenue().getSeats())
		{
PathVec_ERS_Iter3.decision(Event_4f0a931657296fb3a318543c2ea14079.info,14,_mcFreq_d33a41ac104e8c48ca6c8782b5f11bc3,1,0,true);

			if (
PathVec_ERS_Iter3.decision(Event_4f0a931657296fb3a318543c2ea14079.info,14,_mcFreq_d33a41ac104e8c48ca6c8782b5f11bc3,3,4,
PathVec_ERS_Iter3.testCondition(s.isTaken()
))
)
			{
				++numberOfSeatsTaken;
			}
		}
PathVec_ERS_Iter3.decision(Event_4f0a931657296fb3a318543c2ea14079.info,14,_mcFreq_d33a41ac104e8c48ca6c8782b5f11bc3,2,0,true);

}

		
		seatsTaken = numberOfSeatsTaken;
		
		if (
PathVec_ERS_Iter3.decision(Event_4f0a931657296fb3a318543c2ea14079.info,14,_mcFreq_d33a41ac104e8c48ca6c8782b5f11bc3,5,6,
PathVec_ERS_Iter3.testCondition(numberOfSeatsTaken >= getCapacity()
))

				|| 
PathVec_ERS_Iter3.decision(Event_4f0a931657296fb3a318543c2ea14079.info,14,_mcFreq_d33a41ac104e8c48ca6c8782b5f11bc3,7,8,
PathVec_ERS_Iter3.testCondition(numberOfSeatsTaken >= getVenue().getSeats().size()
))
)
		{
			setStatus(EventStatus.Closed);
		}
		else
		{
			setStatus(EventStatus.Open);
		}
	}

	/**
	 * Returns the number of seats currently taken for this event.
	 * @return
	 */
	public int getSeatsTaken() 
	{
int _mcFreq_cba3ef69b2035c5a56e7658d20272ea1[] = new int[1];
PathVec_ERS_Iter3.enterMethod(Event_4f0a931657296fb3a318543c2ea14079.info,15,_mcFreq_cba3ef69b2035c5a56e7658d20272ea1,0);

		return seatsTaken;
	}

	@Override
	public String toString() 
	{
int _mcFreq_cdae8bf5fcd91f9b6209768fec18ee27[] = new int[1];
PathVec_ERS_Iter3.enterMethod(Event_4f0a931657296fb3a318543c2ea14079.info,16,_mcFreq_cdae8bf5fcd91f9b6209768fec18ee27,0);

		SimpleDateFormat wDateFormat = new SimpleDateFormat("yyyy-MM-dd");
		SimpleDateFormat wTimeFormat = new SimpleDateFormat("HH:mm");
		
		return specification.getTitle().toUpperCase() 
				+ " on " + wDateFormat.format(date) 
				+ " at " +  wTimeFormat.format(date)
				+ " lasting " + duration + " minute(s)"
				+ " with capacity of " + capacity + " person(s)"
				+ " and is " + status.toString().toUpperCase()
				+ "; seats available: " + (getCapacity() - getSeatsTaken())
				+ ", Event ID = " + getId();
	}
}
